package wyh.mapper;

import org.apache.ibatis.annotations.*;
import wyh.pojo.User;

import java.util.List;

@Mapper
public interface UserMapper {

    // 验证账号
    @Select("SELECT * FROM users WHERE username = #{username} AND password = #{password}")
    User validateUser(@Param("username") String username, @Param("password") String password);

    // 根据用户名模糊查询用户信息
    @Select("SELECT * FROM users WHERE username LIKE CONCAT('%', #{username}, '%')")
    List<User> getByNameLike(String username);

        // 查询所有用户信息
    @Select("SELECT * FROM users")
    List<User> getAll();

    // 根据用户 ID 查询用户信息
    @Select("SELECT * FROM users WHERE user_id = #{user_id}")
    User getById(Integer user_id);

    // 根据用户 ID 删除用户信息
    @Delete("DELETE FROM users WHERE user_id = #{user_id}")
    int deleteById(Integer user_id);

    // 根据用户 ID 更新用户信息
    @Update("UPDATE users " +
            "SET username = #{username}, password = #{password}, patient_id = #{patient_id}, " +
            "escort_id = #{escort_id}, user_permission = #{user_permission} " +
            "WHERE user_id = #{user_id}")
    int updateById(User user);

    // 插入新用户信息
    @Insert("INSERT INTO users value (null,#{username}, #{password}, #{patient_id}, #{escort_id},#{user_permission})")
    int addUser(User user);
}